<title>产品库</title>

<div class="layui-fluid">
  <div class="layui-card">
    <form class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="LAY_product_form">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">保险公司</label>
          <div class="layui-input-block">
            <select name="brandId" lay-verify="" lay-search>
              <option value="">请选择</option>
            </select>
          </div>
        </div>

        <div class="layui-inline">
          <label class="layui-form-label">产品名称</label>
          <div class="layui-input-block">
            <input type="text" name="productName" placeholder="请输入" autocomplete="off" class="layui-input">
          </div>
        </div>

        <div class="layui-inline">
          <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY_product_search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 查询
          </button>
          <button type="reset" class="layui-btn layuiadmin-btn-useradmin">
            <i class="layui-icon layui-icon-refresh layuiadmin-button-btn"></i> 重置
          </button>
        </div>
      </div>
    </form>

    <div class="layui-card-body">
      <div class="layui-tab" lay-filter="LAY_product_tab">
        <ul class="layui-tab-title" id="LAY_tab_view"></ul>
        <script type="text/html" id="LAY_tab_tpl">
          {{#
          var total = function(){
          var num = 0;
          layui.each(d, function(index, item) {
          num += item.num;
          });
          return num;
          }
          }}
          <li>全部({{total()}})</li>
          {{# layui.each(d, function(index, item) { }}
          <li data-category="{{item.categoryCode}}">
            {{item.name}}({{item.num}})</li>
          {{# }); }}
        </script>
      </div>

      <div class="LAY_product_list" id="LAY_product_list_view">
        <div class="LAY_empty">暂无数据</div>
      </div>

      <script type="text/html" id="LAY_product_list_tpl">
        {{# if (d.datas.length) { }}
        {{# layui.each(d.datas, function(index, item){ }}
        <div class="layui-card" style="margin-top: 15px;">
          <div class="layui-card-body">
            <div class="LAY_product_row">
              <div class="LAY_product_col">
                <div class="LAY_product_titel">
                  {{# if (item.frontFlag && (d.category == 'ORG' || d.category == 'CHANNEL' || d.category == 'CHANNEL_SUB_ACC')) { }}
                  <h2><a class="LAY_url_a LAY_go_view" data-product="{{item.productCode}}" data-src="{{item.pageAddr}}">{{item.productName}}</a></h2>
                  {{# } else { }}
                  <h2>{{item.productName}}</h2>
                  {{# } }}
                  <p title="{{item.belongBrand}}">{{item.belongBrand}}</p>
                </div>
                <ul class="LAY_product_content">
                  {{# layui.each(item.agreement, function(_index, _item){ }}
                  <li>
                    <div class="LAY_product_content_main">
                      <span>●</span> {{_item.benefitName}}
                    </div>
                    <div class="LAY_product_content_side">
                      {{_item.sumInsuredStr}}
                    </div>
                  </li>
                  {{# }); }}
                </ul>
                {{# if (item.agreement && item.agreement.length > 5) { }}
                <a class="LAY_product_more">展开</a>
                {{# } }}
              </div>
              <div class="LAY_product_col LAY_product_middle">
                <div class="LAY_product_describe">{{item.productFeature}}</div>
                <div class="LAY_product_infomation">
                  <h1>{{item.floorPrice}}<span>元起</span></h1>

                  <div class="LAY_product_infomation_list">
                    <div class="LAY_product_infomation_title">
                      佣金结入比例：
                    </div>
                    <div class="LAY_product_infomation_content">
                      <b>{{item.productListCommInDesc || ''}}</b>
                      <button type="button" class="layui-btn layui-btn-xs layui-btn-danger LAY_btn_join_money"
                              data-product="{{item.productCode}}" data-org="{{item.currentOrgCode}}">
                        <i class="layui-icon layui-icon-screen-full"></i>
                      </button>
                    </div>
                  </div>

                  {{# if (d.category == 'ORG' || d.category == 'BROKER_ORG' || d.category == 'TEAM') { }}
                  <div class="LAY_product_infomation_list">
                    <div class="LAY_product_infomation_title">
                      合伙人佣金结出比例：
                    </div>
                    <div class="LAY_product_infomation_content">
                      <b>{{item.productListCommDesc == '-1.00%' ? '未设置' : item.productListCommDesc}}</b>
                      <button type="button" class="layui-btn layui-btn-xs layui-btn-danger LAY_btn_out_money" data-settlePeriod="{{item.settlePeriod}}"
                              data-product="{{item.productCode}}" data-org="{{item.currentOrgCode}}" data-name="{{item.productName}}"
                              data-desc="{{item.productListCommDesc}}" data-way="{{item.commissionWay}}">
                        <i class="layui-icon layui-icon-screen-full"></i>
                      </button>
                    </div>
                  </div>
                  {{# } }}
                </div>
              </div>
              <div class="LAY_product_col">
                <div class="layui-row layui-col-space20 LAY_product_button_group">
                  {{# if (d.category == 'ORG' || d.category == 'BROKER_ORG' || d.category == 'TEAM') { }}
                  {{# if (!item.isJhzb) { }}
                  <div class="layui-col-md6">
                    <button class="layui-btn LAY_btn_join_jhzb" data-code="{{item.productCode}}">移入金惠智保</button>
                  </div>
                  {{# } else { }}
                  <div class="layui-col-md6">
                    <button class="layui-btn layui-btn-danger LAY_btn_remove_jhzb" data-code="{{item.productCode}}">移出金惠智保</button>
                  </div>
                  {{# } }}
                  {{# } }}
                  {{# if (d.category == 'ORG') { }}
                  {{# if (!item.isJhj) { }}
                  <div class="layui-col-md6">
                    <button class="layui-btn LAY_btn_join_jhj" data-code="{{item.productCode}}">移入金惠家保险</button>
                  </div>
                  {{# } else { }}
                  <div class="layui-col-md6">
                    <button class="layui-btn layui-btn-danger LAY_btn_remove_jhj" data-code="{{item.productCode}}">移出金惠家保险</button>
                  </div>
                  {{# } }}
                  {{# } }}
                  {{# if (d.category == 'CHANNEL' || d.category == 'CHANNEL_SUB_ACC') { }}
                  {{# if (!item.isMall) { }}
                  <div class="layui-col-md6">
                    <button class="layui-btn LAY_btn_join_mall" data-code="{{item.productCode}}">移入我的保险商城</button>
                  </div>
                  {{# } else { }}
                  <div class="layui-col-md6">
                    <button class="layui-btn layui-btn-danger LAY_btn_remove_mall" data-code="{{item.productCode}}">移出我的保险商城</button>
                  </div>
                  {{# } }}
                  {{# } }}
                  {{# if (d.category == 'CHANNEL' || d.category == 'CHANNEL_SUB_ACC') { }}
                  <div class="layui-col-md6">
                    <button class="layui-btn LAY_btn_link" data-code="{{item.productCode}}">产品链接</button>
                  </div>
                  {{# } }}
                  {{# if (d.category == 'ORG' || d.category == 'BROKER_ORG' || d.category == 'TEAM') { }}
                  <div class="layui-col-md6">
                    <button class="layui-btn LAY_btn_link_jhzb" data-code="{{item.productCode}}">金惠智保产品链接</button>
                  </div>
                  {{# } }}
                  {{# if (d.category == 'ORG') { }}
                  <div class="layui-col-md6">
                    <button class="layui-btn LAY_btn_link_jhj" data-code="{{item.productCode}}">金惠家保险产品链接</button>
                  </div>
                  {{# } }}
                  {{# if (item.visible == 1) { }}
                  <div class="layui-col-md6">
                    <button class="layui-btn LAY_btn_pc" data-code="{{item.productCode}}">PC投保</button>
                  </div>
                  {{# } }}
                  <div class="layui-col-md6">
                    <a href="{{layui.setter.url}}/product/productDataExport?productCode={{item.productCode}}" class="layui-btn LAY_btn_material">产品资料</a>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        {{# }) }}

        <div id="LAY_product_page" class="LAY_page"></div>
        {{# } else { }}
        <div class="LAY_empty">暂无数据</div>
        {{# } }}
      </script>

    </div>

  </div>
</div>


<script>
  layui.use(['admin', 'form', 'element', 'laypage', 'laytpl', 'qrcode', 'clipboard', 'table', 'getmenus'], function () {
    var $ = layui.$,
            admin = layui.admin,
            setter = layui.setter,
            view = layui.view,
            table = layui.table,
            laytpl = layui.laytpl,
            laypage = layui.laypage,
            element = layui.element,
            form = layui.form,
            getmenus = layui.getmenus;

    var cache = [];
    var params = {
      page: 1,
      pageSize: 10,
      categoryCode: ''
    };
    var tabParams= {};
    var currentTabIndex = 0;

    getTabs(tabParams, function () {
      getProductList(params);
    });

    // 初始化搜索栏
    admin.req({
      url: setter.url + '/product/selectProductCategory',
      type: 'GET',
      done: function (res) {
        var data = res.data || [];

        layui.each(data, function (index, item) {
          var html = '<option value="' + item.brandId + '">' + item.brandName + '</option>'
          $('select[name="brandId"]').append(html);
        });

        // 初始化表单
        form.render(null, 'LAY_product_form');

        // 表单提交
        form.on('submit(LAY_product_search)', function (data) {
          var field = data.field;
          tabParams = $.extend(true, {}, tabParams, field);
          params = $.extend(true, {}, params, { page: 1 }, field);

          getTabs(tabParams, function () {
            getProductList(params);
          });
          return false;
        });
      }
    });

    // 切换选项卡
    element.on('tab(LAY_product_tab)', function(){
      currentTabIndex = $(this).index();
      var categoryCode = $(this).data('category');

      params = $.extend(true, {}, params, {
        page: 1,
        categoryCode: categoryCode || ''
      });

      getTabs(tabParams, function () {
        getProductList(params);
      })
    });

    function renderList(data) {
      renderData(data, function() {
        initEvents();

        pagination(data.pageIndex, data.pageSize, data.recordCounts, function (obj) {
          params = $.extend(true, params, { page: obj.curr, pageSize: obj.limit });
          getProductList(params);
        });
      });
    }

    function getTabs(params, callback) {
      admin.req({
        url: setter.url + '/product/selectProdCategoryNum',
        type: 'GET',
        data: params,
        done: function (res) {
          var data = res.data || [];

          renderTabs(data, function () {
            $('#LAY_tab_view li').eq(currentTabIndex).addClass('layui-this');
            if (typeof(callback) == 'function') {
              callback();
            }
          })
        }
      });
    }

    function renderTabs(data, callback) {
      var getTpl = $('#LAY_tab_tpl').html();
      if (!getTpl) {
        return;
      }
      laytpl(getTpl).render(data, function(html){
        $('#LAY_tab_view').html(html);

        if (typeof(callback) === 'function') {
          callback();
        }
      });
    }

    // 渲染数据
    function renderData(data, callback) {
      var getTpl = $('#LAY_product_list_tpl').html();
      
      if (!getTpl) {
        return;
      }

      laytpl(getTpl).render(data, function(html){
        $('#LAY_product_list_view').html(html);

        if (typeof(callback) === 'function') {
          callback();
        }
      });
    }

    // 产品责任
    function getProduct(productCode, callback) {
      admin.req({
        url: setter.url + '/batchInsure/getBenefitDetails',
        type: 'GET',
        data: { productCode: productCode },
        done: function (res) {
          var data = res.data || [];

          if (typeof(callback) === 'function') {
            callback(data.benefitList);
          }
        }
      });
    }

    // 分页
    function pagination(curr, limit, count, callback) {
      laypage.render({
        elem: 'LAY_product_page'
        ,curr: curr
        ,count: count
        ,limit: limit
        ,prev: '<i class="layui-icon layui-icon-left"></i>'
        ,next: '<i class="layui-icon layui-icon-right"></i>'
        ,layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
        ,jump: function(obj, first){
          if(!first && typeof(callback) === 'function') {
            callback(obj);
          }
        }
      });
    }

    // 产品列表
    function getProductList(query) {
      admin.req({
        url: setter.url + '/product/getProductList',
        type: 'GET',
        data: query,
        done: function (res) {
          var data = res.data || {};
          data.category = sessionStorage.category || 'ORG';

          if (!data.datas || (data.datas && !data.datas.length)) {
            data.datas = [];
            renderList(data);
            return;
          }

          layui.each(data.datas, function (index, item) {
            getProduct(item.productCode, function(agreement) {
              item.agreement = agreement;
              getPcVisible(item.productCode, function (visible) {
                item.visible = visible;
                if (index + 1 >= data.datas.length) {
                  cache = data;
                  renderList(data);
                  initPermission();
                }
              });
            })
          });
        }
      })
    }
    function initPermission() {
      // 移除/接入金惠智保
      var jhzbJoinBtn = $('.LAY_btn_join_jhzb').parent();
      var jhzbRemoveBtn = $('.LAY_btn_remove_jhzb').parent();

      if (!getmenus.isJhzb) {
        jhzbJoinBtn.remove();
        jhzbRemoveBtn.remove();
      }
      // 移除/接入金惠家
      var jhjJoinBtn = $('.LAY_btn_join_jhj').parent();
      var jhjRemoveBtn = $('.LAY_btn_remove_jhj').parent();

      if (!getmenus.isJhj) {
        jhjJoinBtn.remove();
        jhjRemoveBtn.remove();
      }
      // 移除/接入保险商城
      var mallJoinBtn = $('.LAY_btn_join_mall').parent();
      var mallRemoveBtn = $('.LAY_btn_remove_mall').parent();

      if (!getmenus.isMall) {
        mallJoinBtn.remove();
        mallRemoveBtn.remove();
      }
      // 金惠智保产品链接
      var jhzbLinkBtn = $('.LAY_btn_link_jhzb').parent();

      if (!getmenus.jhzbUrl) {
        jhzbLinkBtn.remove();
      }
      // 金惠家保险产品链接
      var jhjLinkBtn = $('.LAY_btn_link_jhj').parent();

      if (!getmenus.jhjUrl) {
        jhjLinkBtn.remove();
      }
      // 金惠家渠道产品链接
      var linkBtn = $('.LAY_btn_link').parent();

      if (!getmenus.jhjchanneUrl) {
        linkBtn.remove();
      }
      // PC投保
      var pcBtn = $('.LAY_btn_pc').parent();

      if (!getmenus.toPc) {
        pcBtn.remove();
      }
      // 产品资料
      var materialBtn = $('.LAY_btn_material').parent();

      if (!getmenus.productInformation) {
        materialBtn.remove();
      }
    }
    function getPcVisible(productCode, callback) {
      admin.req({
        url: setter.url + '/product/productIsPc',
        type: 'GET',
        data: { productCode: productCode },
        done: function (res) {
          var data = res.data || 0;

          if (typeof(callback) === 'function') {
            callback(data);
          }
        }
      });
    }

    function initEvents () {
      // PC投保
      $('.LAY_btn_pc').off('click').on('click', function () {
        var productCode = $(this).data('code');
        location.hash = '/insurance/PCInsurance/productCode=' + productCode;
      });
      // 移入金惠智保
      $('.LAY_btn_join_jhzb').off('click').on('click', function() {
        var productCode = $(this).data('code');
        layer.msg('正在移入', {
          icon: 16,
          time: 1500,
          shade: [0.3, '#393D49']
        }, function(){
          updateIsJhzb({
            productCode: productCode,
            value: 1
          }, function () {
            layui.each(cache.datas, function (index, item) {
              if (item.productCode == productCode) {
                item.isJhzb = 1;
              }
            });

            renderList(cache);
          });
        });
      });

      // 移出金惠智保
      $('.LAY_btn_remove_jhzb').off('click').on('click', function() {
        var productCode = $(this).data('code');

        layer.confirm('你确定将产品移出金惠智保吗？', function(index, layero) {
          layer.msg('正在移出', {
            icon: 16,
            time: 1500,
            shade: [0.3, '#393D49']
          }, function(){
            updateIsJhzb({
              productCode: productCode,
              value: 0
            }, function () {
              layui.each(cache.datas, function (index, item) {
                if (item.productCode == productCode) {
                  item.isJhzb = 0;
                }
              });

              renderList(cache);
            });
          });
        });
      });

      // 移入金惠家
      $('.LAY_btn_join_jhj').off('click').on('click', function() {
        var productCode = $(this).data('code');

        layer.msg('正在移入', {
          icon: 16,
          time: 1500,
          shade: [0.3, '#393D49']
        }, function(){
          updateIsJhj({
            productCode: productCode,
            value: 1
          }, function () {
            layui.each(cache.datas, function (index, item) {
              if (item.productCode == productCode) {
                item.isJhj = 1;
              }
            });

            renderList(cache);
          });
        });
      });

      // 移出金惠家
      $('.LAY_btn_remove_jhj').off('click').on('click', function() {
        var productCode = $(this).data('code');
        layer.confirm('你确定将产品移出金惠家保险吗？', function(index, layero){
          layer.msg('正在移出', {
            icon: 16,
            time: 1500,
            shade: [0.3, '#393D49']
          }, function(){
            updateIsJhj({
              productCode: productCode,
              value: 0
            }, function () {
              layui.each(cache.datas, function (index, item) {
                if (item.productCode == productCode) {
                  item.isJhj = 0;
                }
              });

              renderList(cache);

              layer.close(index);
            });
          });
        });
      });

      // 移入我的保险商城
      $('.LAY_btn_join_mall').off('click').on('click', function() {
        var productCode = $(this).data('code');

        layer.msg('正在移入', {
          icon: 16,
          time: 1500,
          shade: [0.3, '#393D49']
        }, function(){
          updateIsMall({
            productCode: productCode,
            value: 1
          }, function () {
            layui.each(cache.datas, function (index, item) {
              if (item.productCode == productCode) {
                item.isMall = 1;
              }
            });

            renderList(cache);
          });
        });
      });

      // 移出我的保险商城
      $('.LAY_btn_remove_mall').off('click').on('click', function() {
        var productCode = $(this).data('code');

        layer.confirm('你确定将产品移出我的保险商城吗？', function(index, layero){
          layer.msg('正在移出', {
            icon: 16,
            time: 1500,
            shade: [0.3, '#393D49']
          }, function(){
            updateIsMall({
              productCode: productCode,
              value: 0
            }, function () {
              layui.each(cache.datas, function (index, item) {
                if (item.productCode == productCode) {
                  item.isMall = 0;
                }
              });

              renderList(cache);

              layer.close(index);
            });
          });
        });
      });

      // 金惠智保产品链接
      $('.LAY_btn_link_jhzb').off('click').on('click', function() {
        var productCode = $(this).data('code');

        getLink({
          productCode: productCode,
          type: 0
        }, function (data) {
          layer.open({
            title:'金惠智保产品链接'
            ,type: 1
            ,area: admin.screen() < 2 ? ['80%', '300px'] : ['600px', '500px']
            ,shadeClose: true
            ,content: generateLinkLayerContent(data)
            ,success: function(){
              initLinkLayerEvents();
            }
          });
        })
      });

      // 金惠家产品链接
      $('.LAY_btn_link_jhj').off('click').on('click', function() {
        var productCode = $(this).data('code');

        getLink({
          productCode: productCode,
          type: 1
        }, function (data) {
          layer.open({
            title:'金惠家保险产品链接'
            ,type: 1
            ,shadeClose: true
            ,area: admin.screen() < 2 ? ['80%', '300px'] : ['600px', '500px']
            ,content: generateLinkLayerContent(data)
            ,success: function(){
              initLinkLayerEvents();
            }
          });
        })
      });

      // 产品链接
      $('.LAY_btn_link').off('click').on('click', function() {
        var productCode = $(this).data('code');

        getLink({
          productCode: productCode,
          type: 2
        }, function (data) {
          layer.open({
            title:'产品链接'
            ,type: 1
            ,shadeClose: true
            ,area: admin.screen() < 2 ? ['80%', '300px'] : ['600px', '500px']
            ,content: generateLinkLayerContent(data, 2)
            ,success: function(){
              initLinkLayerEvents();
            }
          });
        })
      });

      // 查看详情展示条数
      $('.LAY_product_more').off('click').on('click', function() {
        var hasClass = $(this).prev().hasClass('LAY_product_content_active');

        if (hasClass) {
          $(this).text('展开');
          $(this).prev().removeClass('LAY_product_content_active');
        } else {
          $(this).text('收起');
          $(this).prev().addClass('LAY_product_content_active');
        }
      });
      //产品预览
      $('.LAY_go_view').off('click').on('click',function () {
        var productCode = $(this).data('product'),addr=$(this).data('src');
        if(!addr){
          window.location.href='#/CommodityManagement/H5preview/productCode='+productCode
        }
      })

      // 佣金接入比例
      $('.LAY_btn_join_money').off('click').on('click', function () {
        var productCode = $(this).data('product');
        var currentOrgCode = $(this).data('org');
        var content = '<div class="LAY_layer_table_wrap"><table id="LAY_queryPlanList" lay-filter="LAY_queryPlanList"></table></div>';

        layer.open({
          title:'佣金结入比例'
          ,type: 1
          ,shadeClose: true
          ,area: ['1000px', '500px']
          ,content: content
          ,success: function(){
            table.render({
              elem: '#LAY_queryPlanList'
              ,url: setter.url + '/product/queryPlanList'
              ,where: {
                productCode: productCode,
                currentOrgCode: currentOrgCode
              }
              ,page: false
              ,limit: Number.MAX_VALUE
              ,response: {
                statusCode: 200 //规定成功的状态码，默认：0
              }
              ,cols: [[ //表头
                {field: 'planName', align: 'center', title: '计划名字'}
                ,{field: 'insuranceName', align: 'center', title: '险种名称'}
                ,{field: 'responsibilityName', align: 'center', title: '责任名称'}
                ,{field: 'insPeriod', align: 'center', title: '保障期限', templet: function (d) {
                    var map = {
                      1: d.insPeriod + '天',
                      2: d.insPeriod + '月',
                      3: d.insPeriod + '年',
                      13: '至' + d.insPeriod + '周岁',
                      9999: '保终身'
                    };
                    return map[d.insPeriodType];
                  }}
                ,{field: 'paymentPeriod', align: 'center', title: '缴费期间', templet: function (d) {
                    var map = {
                      1000: '趸交',
                      2: d.paymentPeriod + '个月交',
                      4: d.paymentPeriod + '个月交',
                      3: d.paymentPeriod + '年',
                      13: '至' + d.paymentPeriod + '周岁',
                    };
                    return map[d.paymentPeriodType];
                  }}
                ,{field: 'commissionType', align: 'center', title: '推广费类型', templet: function (d) {
                    var map = {
                      0: '首佣',
                      1: '续佣'
                    };
                    return map[d.commissionType];
                  }}
                ,{field: 'yearNum', align: 'center', title: '保单年度'}
                ,{field: 'accessProportion', align: 'center', title: '我的结入', templet: function (d) {
                    return d.accessProportion + '%';
                  }}
              ]]
            });
          }
        });
      });

      // 佣金结出比例
      $('.LAY_btn_out_money').off('click').on('click', function () {
        debugger
        var productCode = $(this).data('product');
        var currentOrgCode = $(this).data('org');
        var commissionWay = $(this).data('way');
        var productName = $(this).data('name');
        let settlePeriod=$(this).data('settleperiod');
        var map = {
          1: '不结佣',
          2: '系统结佣',
          3: '人工结佣',
          4: '月结',
          5: '认领结佣'
        };
        var productListCommDesc = $(this).data('desc');

        if (productListCommDesc == '-1.00%') {
          var content =
                  '<div class="LAY_layer_table_wrap">' +
                  '<p class="LAY_layer_table_content">您尚未设置给代理人的佣金结出比例</p>';
          if (getmenus.updateProductPolicy) {
            content += '<div class="LAY_layer_btn_group"><button class="layui-btn LAY_layer_btn_set">去设置</button></div>';
          }
          content += '</div>';

          layer.open({
            title:'合伙人佣金结出比例'
            ,type: 1
            ,shadeClose: true
            ,content: content
            ,success: function(){
              $('.LAY_layer_btn_set').off('click').on('click', function () {
                sessionStorage.productName=productName;
                location.hash = '/CommodityManagement/partnerSetCommission/productCode=' + productCode + '/currentOrgCode=' + currentOrgCode;
              });
            }
          });

          return;
        }

        var content =
                '<div class="LAY_layer_table_wrap">' +
                '<table id="LAY_queryPlanList" lay-filter="LAY_queryPlanList"></table>' +
                '<p>结佣方式：' + map[commissionWay] + '</p>' +
                '<p>结佣时效性：生效日期当日 +'+settlePeriod+'天 </p>';
        if (getmenus.updateProductPolicy) {
          content += '<div class="LAY_layer_btn_group"><button class="layui-btn LAY_layer_btn_set">去设置</button></div>';
        }
        content += '</div>';

        layer.open({
          title:'合伙人佣金结出比例'
          ,type: 1
          ,shadeClose: true
          ,area: ['1000px', '500px']
          ,content: content
          ,success: function(){
            table.render({
              elem: '#LAY_queryPlanList'
              ,url: setter.url + '/product/queryPlanList'
              ,page: false
              ,limit: Number.MAX_VALUE
              ,where: {
                productCode: productCode,
                currentOrgCode: currentOrgCode
              }
              ,response: {
                statusCode: 200 //规定成功的状态码，默认：0
              }
              ,cols: [[ //表头
                {field: 'planName', align: 'center', title: '计划名字'}
                ,{field: 'insuranceName', align: 'center', title: '险种名称'}
                ,{field: 'responsibilityName', align: 'center', title: '责任名称'}
                ,{field: 'insPeriod', align: 'center', title: '保障期限', templet: function (d) {
                    var map = {
                      1: d.insPeriod + '天',
                      2: d.insPeriod + '月',
                      3: d.insPeriod + '年',
                      13: '至' + d.insPeriod + '周岁',
                      9999: '保终身'
                    };
                    return map[d.insPeriodType];
                  }}
                ,{field: 'paymentPeriod', align: 'center', title: '缴费期间', templet: function (d) {
                    var map = {
                      1000: '趸交',
                      2: d.paymentPeriod + '个月交',
                      4: d.paymentPeriod + '个月交',
                      3: d.paymentPeriod + '年',
                      13: '至' + d.paymentPeriod + '周岁',
                    };
                    return map[d.paymentPeriodType];
                  }}
                ,{field: 'commissionType', align: 'center', title: '推广费类型', templet: function (d) {
                    var map = {
                      0: '首佣',
                      1: '续佣'
                    };
                    return map[d.commissionType];
                  }}
                ,{field: 'yearNum', align: 'center', title: '保单年度'}
                ,{field: 'accessProportion', align: 'center', title: '我的结入', templet: function (d) {
                    return d.accessProportion ? d.accessProportion + '%' : '';
                  }}
                ,{field: 'outProportion', align: 'center', title: '我的结出', templet: function (d) {
                    return (d.outProportion == '-1.00' || !d.outProportion) ? '' : d.outProportion + '%';
                  }}
              ]]
            });

            $('.LAY_layer_btn_set').off('click').on('click', function () {
              sessionStorage.productName=productName;
              location.hash = '/CommodityManagement/partnerSetCommission/productCode=' + productCode + '/currentOrgCode=' + currentOrgCode;
            });
          }
        });
      });
    }

    //复制文本
    function copyUrl(target){
      var clipboard = new Clipboard(target);
      layer.msg("已复制好，可贴粘。");
    }

    //生成链接弹层内部html
    function generateLinkLayerContent(data, status) {
      var array = [{
        type: 1,
        url: data.wiseUrl
      }, {
        type: 0,
        url: data.url
      }];

      if (status == 2) {
        array = [{
          type: 0,
          url: data.url
        }];
      }

      var content = '<div class="layui-row layui-col-space40 LAY_custom_layer_row">';

      layui.each(array, function(index, item) {
        content += '<div class="LAY_custom_layer_col">' +
                '<div class="LAY_custom_layer_title">' + (item.type ? '智选结论' : '产品详情') + '</div>';
        if (item.url) {
          content += '<div class="LAY_custom_layer_code" data-url="'+ item.url +'"></div>' +
                  '<button type="button" class="layui-btn LAY_custom_layer_copy" data-clipboard-text="'+ item.url +'">' +
                  '<i class="layui-icon layui-icon-unlink"></i> 复制链接' +
                  '</button>';

        } else {
          content += '<div class="LAY_custom_layer_code_empty">暂无' + (item.type ? '智选结论' : '产品详情') + '~</div>'
        }

        content += '</div>';
      });

      content += '</div>';

      return content;
    }

    //初始化链接弹层内事件
    function initLinkLayerEvents() {
      // 二维码
      $('.LAY_custom_layer_code').each(function () {
        var url = $(this).data('url');

        if (url) {
          $(this).qrcode({
            render: 'canvas',
            width: 150,
            height: 150,
            text: url
          });
        } else {
          $(this).html('暂无相关信息');
        }
      });

      // 复制链接
      $('.LAY_custom_layer_copy').off('click').on('click', function () {
        copyUrl('.LAY_custom_layer_copy');
      });
    }

    // 更新是否显示金惠智保状态
    function updateIsJhzb(params, callback) {
      admin.req({
        url: setter.url + '/product/updateIsJhzb',
        type: 'POST',
        data: params,
        done: function (res) {
          layer.msg('操作成功', {
            icon: 1,
            time: 1500,
            shade: [0.3, '#393D49']
          });

          if (typeof(callback) === 'function') {

            callback();
          }
        }
      });
    }

    // 更新是否显示金惠家状态
    function updateIsJhj(params, callback) {
      admin.req({
        url: setter.url + '/product/updateIsJhj',
        type: 'POST',
        data: params,
        done: function (res) {
          layer.msg('操作成功', {
            icon: 1,
            time: 1500,
            shade: [0.3, '#393D49']
          });

          if (typeof(callback) === 'function') {
            callback();
          }
        }
      });
    }

    // 更新是否显示我的商城状态
    function updateIsMall(params, callback) {
      admin.req({
        url: setter.url + '/product/updateIsMall',
        type: 'POST',
        data: params,
        done: function (res) {
          layer.msg('操作成功', {
            icon: 1,
            time: 1500,
            shade: [0.3, '#393D49']
          });

          if (typeof(callback) === 'function') {
            callback();
          }
        }
      });
    }

    // 获取保产品链接
    function getLink(params, callback) {
      admin.req({
        url: setter.url + '/product/productUrl',
        type: 'POST',
        data: params,
        done: function (res) {
          var data = res.data || {};

          if (typeof(callback) === 'function') {
            callback(data);
          }
        }
      });
    }

  });
</script>